<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userName">
              <a-input v-model="model.userName" placeholder="请输入用户名"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="登录名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="loginName">
              <a-input v-model="model.loginName" placeholder="请输入登录名"></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userPwd">
              <a-input v-model="model.userPwd" placeholder="请输入密码"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mobile">
              <a-input v-model="model.mobile" placeholder="请输入手机号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" v-if="title!='新增'">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <j-dict-select-tag type="radio" v-model="model.status" dictCode="member_status" placeholder="请选择状态" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="微信openid" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wxOpenid">
              <a-input v-model="model.wxOpenid" placeholder="请输入微信openid"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="微信unionid" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wxUnionid">
              <a-input v-model="model.wxUnionid" placeholder="请输入微信unionid"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="小程序openid" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xcxOpenid">
              <a-input v-model="model.xcxOpenid" placeholder="请输入小程序openid"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="昵称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nickName">
              <a-input v-model="model.name" placeholder="请输入微信昵称"></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="微信头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avatar">
              <a-input v-model="model.avatar" placeholder="请输入微信头像"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="微信头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avatar">
              <j-image-upload biz-path="laile2/goods" acceptFormat="image/png, image/jpeg" v-model="model.avatar">
              </j-image-upload>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="用户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入用户姓名"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sex">
              <j-dict-select-tag type="radio" v-model="model.sex" dictCode="sex" placeholder="请选择性别" />
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="source">
              <j-dict-select-tag type="radio" v-model="model.source" dictCode="member_source" placeholder="请选择来源" />
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="所属分站" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="siteId">
              <a-input v-model="model.siteId" placeholder="请选择所属分站"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="注册分站" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="siteIdRegist">
              <a-input v-model="model.siteIdRegist" placeholder="请选择注册分站"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="注册经度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="registLat">
              <a-input v-model="model.registLat" placeholder="请输入注册经度"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="注册纬度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="registLng">
              <a-input v-model="model.registLng" placeholder="请输入注册纬度"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-model-item label="下单次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderQty">
              <a-input-number v-model="model.orderQty" placeholder="请输入下单次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单总额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderAnt">
              <a-input v-model="model.orderAnt" placeholder="请输入订单总额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最后下单时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderLast">
              <j-date placeholder="请选择最后下单时间" v-model="model.orderLast"  style="width: 100%" />
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'MemberForm',
  components: {
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    title: String,
  },
  data() {
    return {
      model: {
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        userName: [
          { required: true, message: '请输入用户名!' },
        ],
        loginName: [
          { required: true, message: '请输入登录名!' },
        ],
        userPwd: [
          { required: true, message: '请输入密码!' },
        ],
        mobile: [
          { required: true, message: '请输入手机号!' },
        ],
        //  status: [
        //     { required: true, message: '请输入状态 0正常 1冻结!'},
        //  ],
      },
      url: {
        add: "/member/add",
        edit: "/member/edit",
        queryById: "/member/queryById"
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.visible = true;
    },
    edit(record) {
      this.confirmLoading = true;
      getAction(this.url.queryById, { id: record.id }).then(res => {
        this.model = res.result
        this.$emit('handleChangeThreeElements', {
          site: this.model['siteName']
        })
        this.confirmLoading = false;
      });
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>